//---------------------------------------------------------------------
//  This file is part of the Background Motion solution.
// 
//  Copyright (C) Mindscape (TM).  All rights reserved.
//  http://www.mindscape.co.nz
// 
//  THIS CODE AND INFORMATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY
//  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//  PARTICULAR PURPOSE.
//---------------------------------------------------------------------

using System.Configuration;
using System.Net.Mail;

namespace Mindscape.BackgroundMotion.Website.Infrastructure
{
  /// <summary>
  /// Implementation of a mail sender which sends via the SMTP protocol
  /// </summary>
  public class SmtpMailSender : IMailSender
  {
    /// <summary>
    /// Sends an item of mail from a specific sender to a static recipient
    /// </summary>
    /// <param name="from">The email address of the sender</param>
    /// <param name="subject">The subject of the mail</param>
    /// <param name="body">The body of the mail</param>
    public void Send(string from, string subject, string body)
    {
      SmtpMailSenderConfig config = ConfigurationManager.GetSection("smtpMailSender") as SmtpMailSenderConfig;
      if (config == null) return;

      MailMessage message = new MailMessage(new MailAddress(from), new MailAddress(config.RecipientAddress));
      message.Subject = subject;
      message.Body = body;

      SmtpClient smtp = new SmtpClient();
      smtp.Host = config.Host;
      smtp.Send(message);
    }
  }
}
